package com.kingyea.mobilepolice.util;

import org.springframework.security.crypto.bcrypt.BCrypt;

import java.util.Scanner;

/*
 * BCrypt Java实现
 * BCrypt也是一种哈希算法，相比MD5更安全，速度慢
 * */
public class UseBCrypt {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入密码：");
        String password = scanner.nextLine();//明文
        System.out.println("请输入待验证密码：");
        String candidate = scanner.nextLine();
        // 第一次哈希一个password
        String hashed = BCrypt.hashpw(password, BCrypt.gensalt());//密文

        // gensalt's log_rounds parameter determines the complexity
        // the work factor is 2**log_rounds, and the default is 10
//        String hashed2 = BCrypt.hashpw(password, BCrypt.gensalt(12));
        System.out.println(hashed);
//        System.out.println(hashed2);
        //密码密文匹配检测
        if (BCrypt.checkpw(candidate, hashed))
            System.out.println("It matches");
        else
            System.out.println("It does not match");
    }
}
